package com.ant.storage.controller;


import com.ant.storage.common.ResultPage;
import com.ant.storage.common.ResultVo;
import com.ant.storage.dto.ImgUrlDto;
import com.ant.storage.dto.PurchaseOrdersDto;
import com.ant.storage.dto.PurchaserDto;
import com.ant.storage.dto.SingleDto;
import com.ant.storage.pojo.PurchaseOrders;
import com.ant.storage.service.IPurchaseOrdersService;
import com.ant.storage.vo.PurchaseOrdersVo;
import com.ant.storage.vo.SingleVo;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author melon
 * @since 2022-03-16
 */
@RestController
@RequestMapping("/purchase-orders")
@Api(tags = "采购单列表信息接口")
public class PurchaseOrdersController {

    @Autowired
    private IPurchaseOrdersService purchaseOrdersService;

    @ApiOperation(value = "获取采购单分页信息列表")
    @GetMapping("/getPurchaseOrderPages")
    public ResultVo getPurchaseOrderPages(PurchaseOrdersDto purchaseOrdersDt) {
        ResultPage result = purchaseOrdersService.findPurchaseOrderPage(purchaseOrdersDt);
        return ResultVo.success("获取成功", result);
    }

    @ApiOperation(value = "修改单个物品完成")
    @PostMapping("/modifyPurchaseOrderById")
    public ResultVo modifyPurchaseOrderById(@RequestBody PurchaseOrdersVo  purchaseOrdersVo) {
        return purchaseOrdersService.getPurchaseOrderComplete(purchaseOrdersVo);
    }

    @ApiOperation(value = "采购单完成")
    @PostMapping("/getPurchaseOrderComplete")
    public ResultVo getPurchaseOrderComplete(@RequestBody PurchaseOrdersVo  purchaseOrdersVo) {
        return purchaseOrdersService.getPurchaseOrderComplete(purchaseOrdersVo);
    }


    @ApiOperation(value = "采购单单个物品入库")
    @PostMapping("/findGoodsSingleWarehousing")
    public ResultVo findGoodsSingleWarehousing(@RequestBody PurchaserDto dto) {
        return purchaseOrdersService.findGoodsSingleWarehousing(dto);
    }

    @ApiOperation(value = "采购单物品入库")
    @PostMapping("/findGoodsAndWarehousing")
    public ResultVo findGoodsAndWarehousing(@RequestBody PurchaseOrdersDto purchaseDto) {
        return purchaseOrdersService.findGoodsAndWarehousing(purchaseDto);
    }

    @ApiOperation(value = "修改物品的票据")
    @PostMapping("/updateImgUrl")
    public ResultVo updateImgUrl(@RequestBody ImgUrlDto dto) {
        return purchaseOrdersService.updateImgUrl(dto);
    }

    @ApiOperation(value = "取消采购单单个物品")
    @GetMapping("/findCancelProcure/{id}/{status}")
    public ResultVo findCancelProcure(@PathVariable("id") Integer id, @PathVariable("status") Integer status) {
        purchaseOrdersService.update(new UpdateWrapper<PurchaseOrders>()
                .set("goods_status",status).eq("id",id));
        return ResultVo.success("操作成功");
    }

    @ApiOperation(value = "获取供应商采购明细分页信息")
    @GetMapping("/getPurchaseSupplierOrderPage")
    public ResultVo getPurchaseSupplierOrderPage(PurchaseOrdersDto purchaseOrdersDt) {
        return ResultVo.success("获取成功",purchaseOrdersService.findPurchaseSupplierOrderPage(purchaseOrdersDt));
    }

    @ApiOperation(value = "")
    @GetMapping("/findDetailByIdCensus/{id}")
    public ResultVo findDetailByIdCensus(@PathVariable("id") Integer id) {
        return ResultVo.success("获取成功",purchaseOrdersService.findDetailByIdCensus(id));
    }

    @ApiOperation(value = "采购单退货")
    @PostMapping("/findGoodsRejected")
    public ResultVo findGoodsRejected(@RequestBody PurchaseOrdersDto purchaseDto) {
        return purchaseOrdersService.findGoodsRejected(purchaseDto);
    }

    @ApiOperation(value = "车辆采购单单个物品入库")
    @PostMapping("/findCarWarehousing")
    public ResultVo findCarWarehousing(@RequestBody PurchaserDto dto) {
        return purchaseOrdersService.findCarWarehousing(dto);
    }


    @ApiOperation(value = "查询个人采购入库")
    @GetMapping("/findSingle")
    public ResultVo findSingle() {
        return ResultVo.success("获取成功",purchaseOrdersService.findSingle());
    }

    @ApiOperation(value = "查询个人采购入库")
    @PostMapping("/saveSingle")
    public ResultVo saveSingle(@RequestBody SingleDto dto) {
        return ResultVo.success("获取成功",purchaseOrdersService.saveSingle(dto));
    }

    @ApiOperation(value = "查询计划个人采购入库")
    @GetMapping("/findPlanSingle")
    public ResultVo findPlanSingle() {
        return ResultVo.success("获取成功",purchaseOrdersService.findPlanSingle());
    }


}
